package com.common.uitl;

import android.content.Context;
import android.content.SharedPreferences;

/**
 * 轻量持久化
 * 
 */
public class SharePersistent {

	public static final String PREFS_NAME = Constant.TAG;

	public static void savePerference(Context context, String key, String value) {
		SharedPreferences settings = context
				.getSharedPreferences(PREFS_NAME, 0);
		SharedPreferences.Editor editor = settings.edit();
		editor.putString(key, value);
		editor.commit();
	}

	public static void savePerference(Context context, String key, int value) {
		SharedPreferences settings = context
				.getSharedPreferences(PREFS_NAME, 0);
		SharedPreferences.Editor editor = settings.edit();
		editor.putInt(key, value);
		editor.commit();
	}

	public static void saveBoolean(Context context, String key, boolean value) {
		SharedPreferences settings = context
				.getSharedPreferences(PREFS_NAME, 0);
		SharedPreferences.Editor editor = settings.edit();
		editor.putBoolean(key, value);
		editor.commit();
	}

	public static String getPerference(Context context, String key) {
		SharedPreferences settings = context
				.getSharedPreferences(PREFS_NAME, 0);
		return settings.getString(key, "");
	}

	public static int getInt(Context context, String key) {
		SharedPreferences settings = context
				.getSharedPreferences(PREFS_NAME, 0);
		return settings.getInt(key, 0);
	}

	public static boolean getBoolean(Context context, String key) {
		SharedPreferences settings = context
				.getSharedPreferences(PREFS_NAME, 0);
		return settings.getBoolean(key, false);
	}

	public static boolean getBoolean(Context context, String key,
			boolean defaultVal) {
		SharedPreferences settings = context
				.getSharedPreferences(PREFS_NAME, 0);
		return settings.getBoolean(key, defaultVal);
	}
}
